package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class JDBCDemo7 {
    public static void main(String[] args) {
        try (Connection conn = DBUtil.getConnection();) {
            Statement statement = conn.createStatement();
            String sql = "SELECT COUNT(*) count FROM student s,class c WHERE s.class_id = c.id AND c.name = '1年级1班';";
            ResultSet rs = statement.executeQuery(sql);
            if (rs.next()) {
                int count = rs.getInt("count");//建议用别名
                System.out.println("人数为" + count + "人");
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
    }
}
